﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YasharEl.Infrastructure.ApplicationModel.Modularity.Bootstrap;
using YasharEl.Infrastructure.Diagnostics.Logging;
using YasharEl.Infrastructure.ObjectFactory;
using YasharEl.Infrastructure.ObjectFactory.Unity;
using YasharEl.Infrastructure.ApplicationModel.Modularity;

namespace YasharEl.Infrastructure.ApplicationModel.SmartClient.Modularity
{
    public class UnityModuleBootstrapper : BaseModuleBootstrapper<IModuleComponentBootstrappingExtension>
    {
        public UnityModuleBootstrapper(BaseDependencyContainer container, ILogger<BaseModuleBootstrapper<IModuleComponentBootstrappingExtension>> logger, BaseModule module)
            : base(container, logger, module)
        {
        }

        protected override void ConfigureContainer(System.Configuration.Configuration config)
        {
            UnityDependencyContainer unityDependencyContainer = this.Container as UnityDependencyContainer;
            if (unityDependencyContainer == null)
            {
                throw new InvalidSystemConfigurationException("Unity module bootsrapper must use unity dependency container. Check module loading and bootsrapping logic.");
            }

            if (unityDependencyContainer.InnerContainer == null)
            {
                throw new InvalidSystemConfigurationException("Inner unity container not initialized yet.");
            }

            unityDependencyContainer.InnerContainer.ConfigureUnityContainer(config);
        }
    }
}
